#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
统一API响应工具
简化设计：直接使用字典，避免不必要的对象转换
"""

from typing import Dict, Any, Optional
from datetime import datetime


class ApiResponseHelper:
    """API响应辅助类 - 使用字典而非对象"""
    
    @staticmethod
    def success(data: Any = None, msg: str = "操作成功") -> Dict[str, Any]:
        """成功响应"""
        return {
            "code": 200,
            "success": True,
            "msg": msg,
            "data": data,
            "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        }
    
    @staticmethod
    def error(code: int = 500, msg: str = "操作失败", data: Any = None) -> Dict[str, Any]:
        """错误响应"""
        return {
            "code": code,
            "success": False,
            "msg": msg,
            "data": data,
            "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        }
    

